﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NJL.Web
{
    public partial class GetUserSessions : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string guid = Request.Params["AUTH_GUID"].ToString();
            string strURL = Request.Params["tourl"].ToString();
            string strLoginType = Request.Params["logintype"].ToString();

            ShareSession.ShareSessionFormatter.Deserialize(ShareSession.ShareSessionFormatter.FormatterType.Soap, guid);

            //Response.Write("USER_ID = " + Session["userid"].ToString() + "<br />");
            //Response.Write("USER_NAME = " + Session["username"].ToString() + "<br />");
            //Response.Write("USER_TYPE = " + Session["usertype"].ToString() + "<br />");
            //Response.Write("AUTH_GUID = " + Session["AUTH_GUID"].ToString() + "<br />");

            if (strURL != "")
            {
                if (strLoginType == "opendiv")
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.parent.window.location.href='" + strURL + "';</script>");
                }
                else if (strLoginType == "openwindow")
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.opener.location.href='" + strURL + "';window.close();</script>");
                }
                else if (strLoginType == "opendivwindow")
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.opener.parent.location.href='" + strURL + "';window.close();</script>");
                }
            }
            else
            {
                if (strLoginType == "opendiv")
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.parent.window.location.href='/';</script>");
                }
                else if (strLoginType == "openwindow")
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.opener.location.href='/';window.close();</script>");
                }
                else if (strLoginType == "opendivwindow")
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.opener.parent.location.href='/';window.close();</script>");
                }
            }
        }
    }
}